package com.cf.controller;

import com.cf.entity.Result;
import com.cf.entity.SupportOrder;
import com.cf.service.ItemService;
import com.cf.service.SupportOrderService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
public class SupportOrderController {
    @Autowired
    private SupportOrderService supportOrderService;
    @Autowired
    private ItemService itemService;

    @RequestMapping("/insertSO")
    public Object insertSO(SupportOrder supportOrder){
        int i = supportOrderService.insertSU(supportOrder);
        //传送uuid
        SupportOrder supportOrder1 = supportOrderService.selectBySupport(supportOrder.getOrderid());

        if (i!=0){
            return new Result(200,"添加成功",supportOrder1);
        }

        return new Result(400,"添加失败",null);

    }

    //根据useid查询支持
    @RequestMapping("/subyuserid")
    public Object subyuserid(@RequestParam(defaultValue = "1")int pagenum,
                             @RequestParam(defaultValue = "3")int pagesize, long userid){
        PageInfo<SupportOrder> pageInfo = supportOrderService.SUByuserid(pagenum,pagesize,userid);

        if(pageInfo.getList().size()!=0) {
            return new Result(200, "查询成功", pageInfo);
        }else {
            return new Result(400, "查询成功", null);
        }
    }
    //根据useid查询支持
    @RequestMapping("/delSupport")
    public Object delSupport(SupportOrder supportOrder){
        int i = supportOrderService.delSupportpeo(supportOrder);
        if(i!=0) {
            return new Result(200, "删除成功", null);
        }else {
            return new Result(400, "删除失败", null);
        }
    }
    //根据useid查询支持
    @RequestMapping("/updatestatus")
    public Object updatestatus(String orderuuid){
        int i = supportOrderService.updateStatus(orderuuid);
        if(i!=0) {
            return new Result(200, "交易成功", null);
        }else {
            return new Result(400, "修改失败", null);
        }
    }
}
